//import org.apache.commons.lang3.StringUtils;

//import java.util.ArrayList;
//import java.util.List;

class PigLatinTranslator {

    private final static String[] VowelSound;
    private final static String[] ConsonantSoundMix;
    private final static String[] ConsonantSoundBase;

    static {
        VowelSound = new String[]{
                "yt", "xr", "a", "e", "i", "o", "u"
        };

        ConsonantSoundMix = new String[]{
                "squ", "thr", "sch", "ch", "qu", "th"
        };

        ConsonantSoundBase = new String[]{
                "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"
        };
    }

    String translate(String englishPhrase) {
        String[] englishPhraseSplit = englishPhrase.split(" ");
//        List<String> results = new ArrayList<>();
        StringBuilder results = new StringBuilder();
        String result;
        for (final String english : englishPhraseSplit) {
            result = this.getStartWithFromStringArrays(VowelSound, english);

            if (!result.isEmpty()) {
//                results.add(this.rule1(english));
                results.append(this.rule1(english)).append(" ");
                continue;
            }

            result = this.getStartWithFromStringArrays(ConsonantSoundMix, english);
            if (!result.isEmpty()) {
//                results.add(this.rule2(english, result));
                results.append(this.rule2(english, result)).append(" ");
                continue;
            }

            result = this.getStartWithFromStringArrays(ConsonantSoundBase, english);
            if (!result.isEmpty()) {
//                results.add(this.rule2(english, result));
                results.append(this.rule2(english, result)).append(" ");
            }
        }

//        return StringUtils.join(results, " ");
        return results.deleteCharAt(results.length() - 1).toString(); // delete last BlankSpace
    }

    private String getStartWithFromStringArrays(String[] StringArray, String englishPhrase) {
        for (String startWith : StringArray) {
            if (englishPhrase.startsWith(startWith)) return startWith;
        }
        return new String();
    }

    private String rule1(String englishPhrase) {
        return englishPhrase + "ay";
    }

    private String rule2(String englishPhrase, String consonantSound) {
        return englishPhrase.substring(englishPhrase.indexOf(consonantSound) + consonantSound.length())
                + consonantSound + "ay";
    }
}